<template>
  <div class="user-info">
    <el-form label-width="200px" :model="userInfo">
      <!-- 工号 入职时间 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="工号：">
            <el-input v-model="userInfo.workNumber" class="inputW" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入职时间：">
            <el-date-picker
              v-model="userInfo.timeOfEntry"
              style="width: 300px"
              type="date"
              class="inputW"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 姓名 部门 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="姓名：">
            <el-input v-model="userInfo.username" class="inputW" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="部门：">
            <el-input v-model="userInfo.departmentName" class="inputW" />
          </el-form-item>
        </el-col>
      </el-row>
      <!--手机 聘用形式  -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="手机：">
            <el-input v-model="userInfo.mobile" style="width: 300px" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="聘用形式：">
            <el-select v-model="userInfo.companyId" class="inputW">
              <el-option
                v-for="item in companyList"
                :key="item.id"
                :label="item.val"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 员工照片 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="员工头像：">
            <!-- 放置上传图片 -->
            <UploadImg ref="imgUrl" :reurl="userInfo.staffPhoto" @getImgUrl="getImgUrlFn" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 保存个人信息 -->
      <el-row class="inline-info" type="flex" justify="center">
        <el-col :span="12">
          <el-button type="primary" @click="saveUser">保存更新</el-button>
          <el-button @click="$router.back()">返回</el-button>

        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getUserDetailById } from '@/api/user'
import { saveUserDetailById } from '@/api/employees'
export default {
  name: 'UserInfo',
  data() {
    return {
      userInfo: {},
      companyList: [
        { id: '1', val: '正式' },
        { id: '2', val: '非正式' },
        { id: '3', val: '未知' }

      ]
    }
  },
  created() {
    this.getUserDetailFn()
  },
  methods: {
    getImgUrlFn(imgUrl) {
      this.userInfo.staffPhoto = imgUrl
    },
    async saveUser() {
      const res = await saveUserDetailById(this.userInfo)
      this.$message.success(res.message)
    },
    // 获取个人信息
    async getUserDetailFn() {
      const res = await getUserDetailById(this.$route.query.emoloyeeId)
      console.log(res)
      this.userInfo = res.data
      this.$refs.imgUrl.imageUrl = this.userInfo.staffPhoto
    }
  }
}
</script>

<style scoped lang="scss">
  .user-info{
    padding:30px;
  }
  ::v-deep .el-input__inner {
  height: 36px;
  line-height: 36px;
}
</style>
